package com.yami.shop.webservice.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.yami.shop.bean.model.FundVo;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.webservice.common.service.WapiFundService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 
 * @ClassName:
 * @Description: 资金业务接口
 * @Author:
 * @Date: 2
 * @History 修改描述
 */
@RestController
@RequestMapping( "/wapi/fund")
public class FundWSController {
	private final Logger log = LoggerFactory.getLogger(this.getClass());
	@Autowired
	private WapiFundService wapiFundService;
	/**
	 *
	 * @return
	 * @description: 交易所金额
	 */
	@RequestMapping( "/getWapiFund")
	@ResponseBody
	public ServerResponseEntity<Map<String,Object>> getWapiFund(String userId) {
		try {
			if(StringUtils.isEmpty(userId)){
				throw new YamiShopBindException("yami.user.account.no.exist");
			}
			return  ServerResponseEntity.success(wapiFundService.getWapiFund(userId));
		} catch (Exception e) {
			e.printStackTrace();
			log.error("异常: " + e.getMessage() + "\r\n" + Arrays.toString(e.getStackTrace()));
			throw new YamiShopBindException(e.getMessage());
		}
	}
	/**
	 *
	 * @return
	 * @description: 交易所金额
	 */
	@RequestMapping( "/fundPay")
	@ResponseBody
	public ServerResponseEntity<Map<String,Object>> fundPay() {
		try {
			String busiName = "申购冻结";
			String outBizNo = "123112311123";
			List<FundVo> list = new ArrayList<>();
			FundVo f1 = new FundVo();
			f1.setExecuteNo("1");
			f1.setSettlementAccount("0000000024502");
			f1.setSubTransCode("020305");
			f1.setTransCode("03");
			f1.setExchangeAmount("10");
			FundVo f2 = new FundVo();
			f2.setExecuteNo("2");
			f2.setSettlementAccount("0000000024502");
			f2.setSubTransCode("020302");
			f2.setTransCode("03");
			f2.setExchangeAmount("100");
			list.add(f1);
			list.add(f2);
			JSONObject obj = new JSONObject();
			obj.put("busiName",busiName);
			obj.put("outBizNo",outBizNo);
			obj.put("list",list);
			JSONObject obj1 = wapiFundService.fundPay(obj.toJSONString());
			return  ServerResponseEntity.success((Map<String,Object>)obj1);
		} catch (Exception e) {
			e.printStackTrace();
			log.error("异常: " + e.getMessage() + "\r\n" + Arrays.toString(e.getStackTrace()));
			throw new YamiShopBindException("异常");
		}
	}
		/**
		 *
		 * @return
		 * @description: 交易所金额
		 */
		@RequestMapping( "/fundPa")
		@ResponseBody
		public ServerResponseEntity<Map<String,Object>> fundPa() {
			try {
				String busiName = "解冻";
				String outBizNo = "123112311123";
				List<FundVo> list = new ArrayList<>();
				FundVo f1 = new FundVo();
				f1.setExecuteNo("1");
				f1.setSettlementAccount("0000000024502");
				f1.setSubTransCode("020405");
				f1.setTransCode("04");
				f1.setExchangeAmount("10");
				FundVo f2 = new FundVo();
				f2.setExecuteNo("2");
				f2.setSettlementAccount("0000000024502");
				f2.setSubTransCode("020405");
				f2.setTransCode("04");
				f2.setExchangeAmount("100");
				list.add(f1);
				list.add(f2);

				JSONObject obj = new JSONObject();
				obj.put("busiName",busiName);
				obj.put("outBizNo",outBizNo);
				obj.put("list",list);
				JSONObject obj1 = wapiFundService.fundPay(obj.toJSONString());
				return  ServerResponseEntity.success((Map<String,Object>)obj1);
			} catch (Exception e) {
				e.printStackTrace();
				log.error("异常: " + e.getMessage() + "\r\n" + Arrays.toString(e.getStackTrace()));
				throw new YamiShopBindException("异常");
			}
		}

		/**
		 *
		 * @return
		 * @description: 交易所金额
		 */
		@RequestMapping( "/fundPa1")
		@ResponseBody
		public ServerResponseEntity<Map<String,Object>> fundPa1() {
			try {
				String count = "0000000024502";
				String busiName = "成交";
				String outBizNo = "1231123111";
				List<FundVo> list = new ArrayList<>();
				FundVo f1 = new FundVo();
				f1.setExecuteNo("1");
				f1.setSettlementAccount(count);
				f1.setSubTransCode("120706");
				f1.setTransCode("07");
				f1.setExchangeAmount("1000");
				//货款原子
				FundVo f2 = new FundVo();
				f2.setExecuteNo("2");
				f2.setSettlementAccount(count);
				f2.setSubTransCode("030720");
				f2.setTransCode("07");
				f2.setExchangeAmount("2000");
				list.add(f1);
				list.add(f2);
				//解冻剩下手续费原子
				FundVo f3 = new FundVo();
				f3.setExecuteNo("3");
				f3.setSettlementAccount(count);
				f3.setSubTransCode("020405");
				f3.setTransCode("04");
				f3.setExchangeAmount("500");
				//解冻剩下货款原子
				FundVo f4 = new FundVo();
				f4.setExecuteNo("4");
				f4.setSettlementAccount(count);
				f4.setSubTransCode("020405");
				f4.setTransCode("04");
				f4.setExchangeAmount("1500");
				list.add(f3);
				list.add(f4);
				JSONObject obj = new JSONObject();
				obj.put("busiName",busiName);
				obj.put("outBizNo",outBizNo);
				obj.put("list",list);
				JSONObject obj1 = wapiFundService.fundPay(obj.toJSONString());
				return  ServerResponseEntity.success((Map<String,Object>)obj1);
			} catch (Exception e) {
				e.printStackTrace();
				log.error("异常: " + e.getMessage() + "\r\n" + Arrays.toString(e.getStackTrace()));
				throw new YamiShopBindException("异常");
			}
		}
		/**
		 *
		 * @return
		 * @description: 交易所金额
		 */
		@RequestMapping( "/getWapiFundOutRecord")
		@ResponseBody
		public ServerResponseEntity<Map<String,Object>> getWapiFundOutRecord(String settlementAccount,String tradeCode,String subTransCode,String transOutOrderNo,String createTimeStart,String createTimeEnd ,String fundTransDate,String fundTransDateBegin,String fundTransDateEnd,int pageSize,int currentpage) {
			try {

				JSONObject obj = new JSONObject();
				obj.put("settlementAccount",settlementAccount);
				obj.put("tradeCode",tradeCode);
				obj.put("subTransCode",subTransCode);
				obj.put("transOutOrderNo",transOutOrderNo);
				obj.put("createTimeStart",createTimeStart);
				obj.put("createTimeEnd",createTimeEnd);
				obj.put("fundTransDate",fundTransDate);
				obj.put("fundTransDateBegin",fundTransDateBegin);
				obj.put("fundTransDateEnd",fundTransDateEnd);
				obj.put("pageSize",pageSize);
				obj.put("currentpage",currentpage);
				JSONObject obj1 = wapiFundService.getWapiFundOutRecord(obj.toJSONString());
				return  ServerResponseEntity.success((Map<String,Object>)obj1);
			} catch (Exception e) {
				e.printStackTrace();
				log.error("异常: " + e.getMessage() + "\r\n" + Arrays.toString(e.getStackTrace()));
				throw new YamiShopBindException(e.getMessage());
			}
		}

}